;;; This file is part of guix-bavier.git
;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
;;; License: GPLv3+

(define-module (bavier packages rdesktop)
  #:use-module (guix download)
  #:use-module (guix packages)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages assembly)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages base)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages image)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages mp3)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xiph)
  #:use-module (gnu packages xorg)
  #:use-module ((guix licenses) #:prefix license:))

(define-public xrdp
  (package
    (name "xrdp")
    (version "0.9.13.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/neutrinolabs"
                                  "/xrdp/releases/download/v" version
                                  "/xrdp-" version ".tar.gz"))
              (sha256
               (base32
                "130hhjqhd8a2xbj012ivhq0yh8ji86ciiddkj653f3069i01a2p9"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("nasm" ,nasm)))
    (inputs
     `(("fuse" ,fuse)                   ; For clipboard file redirection
       ("openssl" ,openssl)
       ("opus" ,opus)
       ("lame" ,lame)
       ("libfdk" ,libfdk)
       ("libjpeg-turbo" ,libjpeg-turbo)
       ("libx11" ,libx11)
       ("libxfixes" ,libxfixes)
       ("libxrandr" ,libxrandr)
       ("linux-pam" ,linux-pam)
       ("pixman" ,pixman)))
    (arguments
     `(#:configure-flags
       (list "--enable-opus"
             "--enable-mp3lame"
             "--enable-fdkaac"
             "--enable-fuse"
             "--enable-pixman"
             "--enable-jpeg"
             "--enable-tjpeg"
             (string-append "TURBOJPEG_PATH="
                            (assoc-ref %build-inputs "libjpeg-turbo"))
             "--enable-pam"
             ;; "--enable-pamuserpass"
             "--enable-pam-config=unix"
             "--enable-strict-locations"
             (string-append "--sysconfdir=" %output "/etc")
             (string-append "--localstatedir=/var"))))
    (home-page "http://xrdp.org")
    (synopsis "Remote Desktop Protocol server")
    (description "@code{xrdp} provides a graphical login to remote machines
using @acronym{RDP,Microsoft Remote Desktop Protocol}.  @code{xrdp} accepts
connections from variety of RDP clients: FreeRDP, rdesktop, NeutrinoRDP and
Microsoft Remote Desktop Client.  xrdp supports not only graphics remoting but
also two-way clipboard transfer (text, bitmap, file), audio redirection, and
drive redirection (mount local client drives on remote machine).  Transport is
encrypted using TLS by default.")
    (license license:asl2.0)))

(define-public xorgxrdp
  (package
    (name "xorgxrdp")
    (version "0.2.13")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/neutrinolabs"
                                  "/xorgxrdp/releases/download/v" version
                                  "/xorgxrdp-" version ".tar.gz"))
              (sha256
               (base32
                "0h58yhaw16vmxf8gkmvb03qhqq4d6z5za3vif9csj35d4bygy5ii"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("nasm" ,nasm)              ; Uses SSE2 asm for x86[_64]
       ;; For xorg-test-run.sh:
       ("which" ,which)
       ("xdpyinfo" ,xdpyinfo)))
    (inputs
     `(("libepoxy" ,libepoxy)
       ("libxfont" ,libxfont2)
       ("xorg-server" ,xorg-server)
       ("xrdp" ,xrdp)))
    (arguments
     `(#:configure-flags (list "--enable-strict-locations"
                               "--enable-glamor")))
    ;; TODO: Maybe need to add a section like:
    ;;
    ;; Section "Files"
    ;; ModulePath      "%out/lib/xorg/modules"
    ;; EndSection
    (home-page (package-home-page xrdp))
    (synopsis "Xorg drivers for xrdp")
    (description "@code{xorgxrdp} is a collection of modules to provide RDP
support for use with a pre-existing X.Org server.  @code{xorgxrdp} is the
preferred backend for @code{xrdp}.")
    (license license:x11)))
